<?php
/*
 *@通过curl方式获取指定的图片到本地
 *@ 完整的图片地址
 *@ 要存储的文件名
 */
function curlDowImg($url = "")
{
    //去除URL连接上面可能的引号
    $hander = curl_init();
    $agent = 'Mozilla/5.0 (compatible; Baiduspider/' . rand(1, 9999) . '.' . rand(1, 9999) . '; +http://www.baidu.com/search/spider.html)';

    curl_setopt($hander, CURLOPT_USERAGENT, $agent);
    curl_setopt($hander, CURLOPT_URL, $url);
    curl_setopt($hander, CURLOPT_HEADER, 0);
    curl_setopt($hander, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($hander, CURLOPT_FOLLOWLOCATION, 1);
    //curl_setopt($hander,CURLOPT_RETURNTRANSFER,false);//以数据流的方式返回数据,当为false是直接显示出来
    curl_setopt($hander, CURLOPT_TIMEOUT, 60);
    $rs = curl_exec($hander);
    $errno = curl_errno($hander);
    $error = curl_error($hander);
    $info = curl_getinfo($hander);
    curl_close($hander);
    $data = array($errno, $error, $info);
    return $data;
}

$src= 'http://wx.qlogo.cn/mmopen/pticn0KViaKD3z451dEiaUicGEIAkmKFibqf03XJz7vOtFOzfFgypicgrKdX3KFGEPJfCGnApydiblFGl7v9qwe8PWiahkicic5WRdHvvic/0';
$failed = 0;
$i = 1;
do
{
    echo $i . ' ';
    $data = curlDowImg($src);
    if (0 != $data[0]) 
    {
        var_dump($i, $data);
        $failed++;
    }
    $i++;
    echo "<br/>";
} while(5 > $failed && 1000 > $i);
